package com.ysyc.driver_ee.activity;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.LinearLayout;

import com.tamic.jswebview.browse.JsWeb.CustomWebViewClient;
import com.tamic.jswebview.view.ProgressBarWebView;
import com.ysyc.driver_ee.R;
import com.ysyc.driver_ee.base.BaseActivity;
import com.ysyc.driver_ee.widget.TitleView;


import java.util.Map;

import butterknife.BindView;

/**
 * Created by yanhan on 2018/4/5/005.
 * 消息的详情webview页面
 */

public class WebViewActivity extends BaseActivity {

    public static final String WEBVIEW_URL = "params_url";

    public static final String TITLE_NAME = "title_name";

    @BindView(R.id.web_view)
    ProgressBarWebView webView;
    @BindView(R.id.rootLl)
    LinearLayout rootLl;
    @BindView(R.id.titleView)
    TitleView titleView;

    public String url;
    public String titleContent;
    private String titleName;

    @Override
    protected void initView() {
        Intent intent = getIntent();
        url = intent.getStringExtra(WEBVIEW_URL);
        titleContent = intent.getStringExtra(TITLE_NAME);

        titleView.setTitle(titleContent);
        titleView.setLeftImg(R.drawable.left_return_icon);
        titleView.setLeftImgClick(view -> finish());
        webView.setWebViewClient(new CustomWebViewClient(webView.getWebView()) {
            @Override
            public String onPageError(String url) {
                return null;
            }

            @NonNull
            @Override
            public Map<String, String> onPageHeaders(String url) {
                return null;
            }
        });

        //设置加载进度条的颜色
        webView.getProgressBar().setReachedBarColor(getResources().getColor(R.color.c_fb8416));

        if (!TextUtils.isEmpty(url)) {
            webView.loadUrl(url);
        }

  /*      webView.registerHandler("over", (handlerName, responseData, function) -> {
            if (handlerName.equals("over")) {
                finish();
            }
        });*/


    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_webview;
    }


    @Override
    protected void onDestroy() {
        webView.getWebView().removeAllViews();
        webView.getWebView().destroy();
        super.onDestroy();
    }

}
